<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='https://cdn.staticfile.org/react/16.4.0/umd/react.development.js'></script>
    <script src='https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js'></script>
    <!-- 生产环境中不建议使用 -->
    <script src='https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js'></script>
<!-- PropTypes文件 -->
<script src='https://unpkg.com/prop-types@15.6.2/prop-types.js'></script>
</head>

<body>
    <div id='app'>
    </div>
    <script type='text/babel'>
        /*
            也许看到这一小节的标题你会感到奇怪，怎么做到不用柯里化也能实现输入框内容拿到后统一处理呢？其实很简单，你想一下，我们的onChange事件的值只能是函数对不对，然后这个函数还会接收到一个currentNode参数对不对，那你想，如果我把onChange的值写成一个箭头函数，这个箭头函数是不是就能接收到currentNode，紧接着在里面调用saveData，不就实现了同时接收到currentNode和key了吗？
        */
        class Demo extends React.Component{
            state = {
                username:'',
                password:''
            }
            saveData = (key,value)=>{
                this.setState({[key]:value})
            }

            render(){
                return (
                    <div>
                        <input type="text" onChange={node=>this.saveData('username',node.target.value)}/>
                        <input type="text" onChange={node=>this.saveData('password',node.target.value)}/>
                        <button onClick={()=>{console.log(this.state)}}>测试</button>
                    </div>
                )
            }
        }

        ReactDOM.render(<Demo/>,document.getElementById('app'))
    </script>
</body>

</html>